﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using ZDSoft.UPMS.Model.BusinessPart;
using NHibernate.Criterion;
using NHibernate;
using Castle.ActiveRecord;

namespace ZDSoft.UPMS.Manager.BusinessPart
{
    public class TermManager:ManagerBase<Term>
    {
        public Term GetCurrentTerm()
        {
            IList<ICriterion> condition = new List<ICriterion>();
            condition.Add(Expression.Lt("StopTime", DateTime.Now));
            condition.Add(Expression.Gt("StartTime", DateTime.Now));
            IList<Term> list = base.Find(condition);
            return list.FirstOrDefault();
        }

        public Term GetCurrentTerm1()
        {
            //IList<ICriterion> condition = new List<ICriterion>();
            //condition.Add(Expression.Lt("StopTime", DateTime.Now));
            //condition.Add(Expression.Gt("StartTime", DateTime.Now));
            //IList<Term> list = Find(condition);
            //Term t= list.FirstOrDefault();
            //return t;
            ISession session = ActiveRecordBase.holder.CreateSession(typeof(TermManager));
            IList<Term> ts = session.CreateQuery("from Term where StartTime<GETDATE() and StopTime>GETDATE()").List<Term>();
            Term t = ts.FirstOrDefault();
            return t;
        }
    }
}
